package com.sunagy.demand.front.utils;

import java.util.Random;

/**
 * desc：#TODO fill me ！
 * author：三餘無夢生
 * date：2018/4/27
 * time：下午5:57
 */
public class NonceUtil {
    public static String generate() {
        String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        int baseLen = base.length();
        for (int i = 0; i < 18; i++) {
            int number = random.nextInt(baseLen);
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    public static String invitation() {
        //字符源，可以根据需要删减
        String generateSource = "0123456789abcdefghgklmnpqrstuvwxyz";//去掉1和i ，0和o
        String rtnStr = "";
        for (int i = 0; i < 6; i++) {
            //循环随机获得当次字符，并移走选出的字符
            String nowStr = String.valueOf(generateSource.charAt((int) Math.floor(Math.random() * generateSource.length())));
            rtnStr += nowStr;
            generateSource = generateSource.replaceAll(nowStr, "");
        }
        return rtnStr;
    }
}
